package com.giaothong.view;

import java.util.List;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import com.giaothong.R;
import com.giaothong.entities.Question;

public class BienBaoGridAdapter extends BaseAdapter {
	
	private String TAG = "BienBaoAdapter";
	private Context mContext;
	private List<Question> mListQuestion;
	private int position;

	public BienBaoGridAdapter(Context context, List<Question> list) {
		mContext = context;
		mListQuestion = list;

	}

	@Override
	public int getCount() {
		return mListQuestion.size();
	}

	@Override
	public Object getItem(int pos) {
		return mListQuestion.get(pos);
	}

	@Override
	public long getItemId(int pos) {
		return pos;
	}

	@Override
	public View getView( int pos, View convertView, ViewGroup parent) {
		// get selected entry
		Question question = mListQuestion.get(pos);
		
		// inflating list view layout if null
		if(convertView == null) {
			LayoutInflater inflater = LayoutInflater.from(mContext);
			convertView = inflater.inflate(R.layout.bienbao_isgridview, null);
			// set bien bao
			ImageView imgBienBao = (ImageView)convertView.findViewById(R.id.imgbienbao);
			int idPatchQuestion = mContext.getResources().getIdentifier(question.getImage().trim(), "drawable", mContext.getPackageName());
			if(idPatchQuestion > 0){
				Log.i(TAG,"Hinh Bien Bao" +question.getImage());
				imgBienBao.setBackgroundDrawable(mContext.getResources().getDrawable(idPatchQuestion));
			}
		}
		
		return convertView;
	}
}
